from PyQt5.QtCore import Qt,QTime
from PyQt5.QtWidgets import QWidget,QApplication, QMessageBox,QLineEdit
from PyQt5.QtGui import QPixmap
import sys  # 导入 sys 库
import time  # 导入 time 库
import win32gui  # 导入 win32gui 库

from package.Utils.MainWindow import mywinutils,img_relative_path
from package.ui.QT_AdvancedSetWindow import Ui_Dialog  # 导入Ui_Dialog类(QT设计师创建)
from package.Utils.User_Thread import mythread  # 导入 mythread 对象(python代码)
from package.Utils.Screen import screen,filter   # 导入 screen 对象(python代码)
from package.Utils.log import logger,mylog  # 导入 logger 对象(python代码)
from package.Utils.config import config_obj  # 导入 config_obj 对象(python代码)

class MyAdvancedSetWindow(QWidget, Ui_Dialog): # 继承 QWidget类和 Ui_Dialog界面类
    def __init__(self, parent=None):
        super(MyAdvancedSetWindow, self).__init__(parent)
        self.setupUi(self)  # 初始化界面

        self.setWindowFlags(Qt.WindowStaysOnTopHint)  # 窗口置顶

        self.time = QTime(mywinutils.Time_H, mywinutils.Time_M)  # 设置时间
        self.timeEdit.setTime(self.time)

    def accept(self):
        if mylog.log_enabled is True:
            logger.info("退出高级设置界面")  # 记录日志
        self.close()  # 关闭窗口

    def click_pushButton_Save(self):

        mywinutils.Time_H = self.timeEdit.time().hour()  # 获取时间 时
        mywinutils.Time_M = self.timeEdit.time().minute()  # 获取时间 分
        mywinutils.time_msg = self.lineEdit_time_msg.text()  # 获取提醒信息

        if mylog.log_enabled is True:
            logger.info("保存成功！")  # 记录日志

        #保存配置
        config_obj.config_text['HotKey'] = mywinutils.Shortcut_key# 保存配置
        config_obj.config_text['log_Enable'] = mylog.log_enabled  # 保存配置
        config_obj.config_text['hwnd'] = mywinutils.hwnd  # 保存窗口句柄
        config_obj.config_text['Time_H'] = mywinutils.Time_H  # 保存配置
        config_obj.config_text['Time_M'] = mywinutils.Time_M  # 保存配置
        config_obj.config_text['Time_MSG'] = mywinutils.time_msg  # 保存配置
        config_obj.write(config_obj.config_text)

        self.close()  # 关闭窗口

